package com.shine.ws.client;

import com.shine.ws.client.util.ClientLoginInterceptor;
import com.shine.ws.service.IMessageService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

/**
 * @Description: 基于代理实现WebService客户端调用
 * @CreateTime: 2023/7/17 10:34
 * @Version:
 * @Since: 1.8
 * @Author: Forward Seen
 */
public class CXFClientProxy {
    public static void main(String[] args) {
        String address = "http://127.0.0.1:8080/services/MessageService?wsdl";
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setAddress(address);//代理地址
        jaxWsProxyFactoryBean.setServiceClass(IMessageService.class);//映射的接口
        jaxWsProxyFactoryBean.getOutInterceptors().add(
            new ClientLoginInterceptor("forward","password")//设置认证数据
        );
        IMessageService messageService = (IMessageService) jaxWsProxyFactoryBean.create();//远程接口映射
        String message = "这是一条来自客户端的消息";
        String result = messageService.echo(message);//业务调用
        System.out.println(result);
    }
}